package com.lmx.common.context;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.web.socket.WebSocketSession;

import com.google.common.collect.Maps;
import com.lmx.log.LogQueue;
import com.lmx.message.MessageQueue;
import com.lmx.repoDomain.tmodel.Call;
import com.lmx.repoDomain.tmodel.Dicttype;
import com.lmx.repoDomain.tmodel.UserSession;
import com.lmx.repoDomain.tmodel.unpersis.ExportParam;
import com.lmx.repoDomain.tmodel.unpersis.ExportThreadParam;
import com.lmx.repoDomain.tmodel.unpersis.SubmitParam;
import com.lmx.repoDomain.tmodel.unpersis.TempVerificationCode;
import com.lmx.repoDomain.tmodel.weixin.WeixinAccessToken;

@SuppressWarnings("unchecked")
public class ActionContextHolder {
	private static ThreadLocal contextHolder = new ThreadLocal();

	// private static Map<String,User> evaHolder = new HashMap(); //<token,user>

    private static Map<String, UserSession> evaHolder = new HashMap(); // <token,userSession>

	private static Map<String, String> uidTokenHolder = new HashMap<>(); // <uid,token>

	private static Map<String, String> authCodeHolder = new HashMap<String, String>();// <token,mobile/mail>

	private static Map<String, Dicttype> dicctypeHolder = new HashMap<String, Dicttype>(); // <typecode,typename>

	private static Map<String, Call> callHolder = new HashMap<String, Call>();// <agentNumber,call>

	private static String baseTokenHolder = "";// 华为 Base token

	private static Map<String, WeixinAccessToken> watHolder = new HashMap(); // <token,WeixinAccessToken>

	private static Map<String, ExportThreadParam> exportThreadMap = Maps.newHashMap();

	private static MessageQueue messageQueue = new MessageQueue();// 通知消息队列

	private static LogQueue logQueue = new LogQueue();// 日志队列

	private static ExportParam exportParam; // 导出参数

	private static String showFlag = "";// 演示标识

	private static List<String> callingList = new ArrayList<String>();// 未复位的按键列表

	private static String beaconRelations = "";// 手环按键对应关系

	private static Map<String, SubmitParam> submitParams = Maps.newHashMap();// 保存请求的请求信息暂存(用于避免重复提交)

	private static List<String> planModelList = new ArrayList<String>();// 护理模版未完成列表
	
	private static Map<String, Integer> localServerFlag = Maps.newHashMap();// value:保存本地服务最近一次发送数据时间 key:呼叫本地服务serverFlag
	
	private static Map<String, List<WebSocketSession>> uidSocketSessionHolder = new HashMap(); // <uid,WebSocketSession>
	
	private static Map<String, WebSocketSession> localSocketSessionHolder = new HashMap(); // <本地视频服务tenantCode,WebSocketSession>
	
	private static Map<String, List<String>> tokenCameraHolder = Maps.newHashMap();//<token,CameraCodeList>
	
	private static Map<String, String> socketTokenHolder = Maps.newHashMap();//<pc/移动端socketsession.hashcode,token>
	
	private static Map<String, List<String>> cameraTokenHolder = Maps.newHashMap(); // <CameraCode,tokenList>
	
	public static Map<String, String> getSocketTokenHolder() {
		return socketTokenHolder;
	}

	public static void setSocketTokenHolder(Map<String, String> socketTokenHolder) {
		ActionContextHolder.socketTokenHolder = socketTokenHolder;
	}

	public static Map<String, List<String>> getCameraTokenHolder() {
		return cameraTokenHolder;
	}

	public static void setCameraTokenHolder(Map<String, List<String>> cameraTokenHolder) {
		ActionContextHolder.cameraTokenHolder = cameraTokenHolder;
	}

	public static Map<String, List<String>> getTokenCameraHolder() {
		return tokenCameraHolder;
	}

	public static void setTokenCameraHolder(Map<String, List<String>> tokenCameraHolder) {
		ActionContextHolder.tokenCameraHolder = tokenCameraHolder;
	}

	public static Map<String, Integer> getLocalServerFlag() {
		return localServerFlag;
	}

	public static void setLocalServerFlag(Map<String, Integer> localServerFlag) {
		ActionContextHolder.localServerFlag = localServerFlag;
	}

	public static Integer getHuamiDateFlag() {
		return huamiDateFlag;
	}

	public static void setHuamiDateFlag(Integer huamiDateFlag) {
		ActionContextHolder.huamiDateFlag = huamiDateFlag;
	}

	private static Integer huamiDateFlag = 0;// 华米数据发送标识

	private static Map<String, TempVerificationCode> tempCode = Maps.newHashMap();// 手机验证验证码

	public static List<String> getPlanModelList() {
		return planModelList;
	}

	public static void setPlanModelList(List<String> planModelList) {
		ActionContextHolder.planModelList = planModelList;
	}

	public static String getBeaconRelations() {
		return beaconRelations;
	}

	public static void setBeaconRelations(String beaconRelations) {
		ActionContextHolder.beaconRelations = beaconRelations;
	}

	public static List<String> getCallingList() {
		return callingList;
	}

	public static void setCallingList(List<String> callingList) {
		ActionContextHolder.callingList = callingList;
	}

	public static String getShowFlag() {
		return showFlag;
	}

	public static void setShowFlag(String showFlag) {
		ActionContextHolder.showFlag = showFlag;
	}

	public static Map<String, List<WebSocketSession>> getUidSocketSessionHolder() {
		return uidSocketSessionHolder;
	}

	public static void setUidSocketSessionHolder(
			Map<String, List<WebSocketSession>> uidSocketSessionHolder) {
		ActionContextHolder.uidSocketSessionHolder = uidSocketSessionHolder;
	}

	public static MessageQueue getMessageQueue() {
		return messageQueue;
	}

	public static void setMessageQueue(MessageQueue messageQueue) {
		ActionContextHolder.messageQueue = messageQueue;
	}

	public static LogQueue getLogQueue() {
		return logQueue;
	}

	public static void setLogQueue(LogQueue logQueue) {
		ActionContextHolder.logQueue = logQueue;
	}

	public static String getBaseTokenHolder() {
		return baseTokenHolder;
	}

	public static void setBaseTokenHolder(String baseTokenHolder) {
		ActionContextHolder.baseTokenHolder = baseTokenHolder;
	}

	public static Map<String, UserSession> getEvaHolder() {
		return evaHolder;
	}

	public static void setEvaHolder(Map<String, UserSession> evaHolder) {
		ActionContextHolder.evaHolder = evaHolder;
	}

	public static Map<String, WeixinAccessToken> getWatHolder() {
		return watHolder;
	}

	public static void setWatHolder(Map<String, WeixinAccessToken> watHolder) {
		ActionContextHolder.watHolder = watHolder;
	}

	public static Map<String, String> getUidTokenHolder() {
		return uidTokenHolder;
	}

	public static void setUidTokenHolder(Map<String, String> uidTokenHolder) {
		ActionContextHolder.uidTokenHolder = uidTokenHolder;
	}

	public static Map<String, String> getAuthCodeHolder() {
		return authCodeHolder;
	}

	public static void setAuthCodeHolder(Map<String, String> authCodeHolder) {
		ActionContextHolder.authCodeHolder = authCodeHolder;
	}

	public static Map<String, Dicttype> getDicctypeHolder() {
		return dicctypeHolder;
	}

	public static void setDicctypeHolder(Map<String, Dicttype> dicctypeHolder) {
		ActionContextHolder.dicctypeHolder = dicctypeHolder;
	}

	public static Map<String, Call> getCallHolder() {
		return callHolder;
	}

	public static void setCallHolder(Map<String, Call> callHolder) {
		ActionContextHolder.callHolder = callHolder;
	}

	public static void setContext(ActionParamsContext context) {
		contextHolder.set(context);
	}

	public static ActionParamsContext getContext() {
		if (contextHolder.get() == null) {
			contextHolder.set(new ActionParamsContext());
		}
		return (ActionParamsContext) contextHolder.get();
	}

	public static ExportParam getExportParam() {
		return exportParam;
	}

	public static void setExportParam(ExportParam exportParam) {
		ActionContextHolder.exportParam = exportParam;
	}

	public static void putExportThreadParam(String key, ExportThreadParam threadParam) {
		ActionContextHolder.exportThreadMap.put(key, threadParam);
	}

	public static ExportThreadParam getExportThreadParam(String key) {
		return ActionContextHolder.exportThreadMap.get(key);
	}

	public static Map<String, ExportThreadParam> getExportThreadMap() {
		return ActionContextHolder.exportThreadMap;
	}

	public static Map<String, SubmitParam> getSubmitParams() {
		return ActionContextHolder.submitParams;
	}

	public static void putSubmitParams(String token, SubmitParam param) {
		ActionContextHolder.submitParams.put(token, param);
	}

	public static Map<String, TempVerificationCode> getTempCode() {
		return tempCode;
	}

	public static void putTempCode(String mobileNum, TempVerificationCode codeEntity) {
		ActionContextHolder.tempCode.put(mobileNum, codeEntity);
	}
	
    public static Map<String, WebSocketSession> getLocalSocketSessionHolder() {
        return localSocketSessionHolder;
    }

    public static void setLocalSocketSessionHolder(Map<String, WebSocketSession> localSocketSessionHolder) {
        ActionContextHolder.localSocketSessionHolder = localSocketSessionHolder;
    }	
}
